layui.use(['form','layer'],function(){
	let layer = parent.layer === undefined ? layui.layer : parent.layer,
		$ = layui.jquery;

	//获取项目名称
	let pathname = window.document.location.pathname;
	let path = pathname.substring(0,pathname.lastIndexOf("/"));

	//背景图片自动轮播
	let i = 2;
	setInterval(function () {
		$("body").css({
			transition: "all 1.5s",
			"-moz-transition": "all 1.5s",
			backgroundImage: 'url("'+path+'/static/images/loginbg/' + i + '.jpg")',
			backgroundSize: "100% 100%"
		});
		if (i >=3) {
			i=1;
		}else {
			i++;
		}
	}, 5000);



	//验证码刷新
	$("#codePic").click(function () {
		$(this).attr("src",path+"/getVCode?r="+Math.random());
	});

	//光标定位到用户名输入框
	$("#username").focus();




	//登录按钮事件
	$("#loginBtn").click(function () {
		if ($("#username").val()==null||$("#username").val()=="") {
			layer.msg("请输入用户名");
			return false;
		} else if ($("#password").val()==null||$("#password").val()=="") {
			layer.msg("请输入密码");
			return false;
		} else if ($("#code").val()==null||$("#code").val()=="") {
			layer.msg("请输入验证码");
			return false;
		}else {
			$("#login_form").submit();
		}
	});
});
